import { Router } from "express";
import { IcallbackFn, Ioracle } from "../../types";

export default (router:Router,oracle:Ioracle,callbackFn:IcallbackFn) => {

  //抓取盘点/盘差报告
  router.post("/getApproveList",(req,res) => {
    const { account } = req.body
    let sql = " select rownum,a.header_id,a.dept_code "
    sql += " ,d.chinese_name "
    sql += " ,to_char(a.updated_date,'yyyymmdd hh24:mi:ss') check_date "
    sql += " ,c.chinese_name action_klm "
    sql += " from xx_general_asset_check_header a,xx_general_asset_check_flow b "
    sql += " ,user_info_n c,user_info_n d "
    sql += " where a.header_id = b.header_id "
    sql += " and a.current_seq = b.current_seq "
    sql += " and b.action_klm = c.account "
    sql += " and a.updated_by = d.account "
    sql += " and nvl(a.flow_phase,'E') <> 'close' "
    sql += " and a.flow_phase = '主管簽核' "
    if(account === "xdomain\\sychien"){
      sql += ` and (b.action_klm = '${account}' or b.action_klm = 'xdomain\\1sychien')`
    }
    else{
      sql += ` and b.action_klm = '${account}' `
    }
    callbackFn(res,oracle.connChaos,{sql})
  })

  //抓取未盘点细项
  router.post("/getApproveAbnormal",(req,res) => {
    const { headerId } = req.body
    let sql = " select rownum seq,asset_no,asset_name,asset_qty "
    sql += " ,lose_reason,lose_action "
    sql += " from xx_general_asset_check_line "
    sql += " where header_id = '"+ headerId +"' "
    sql += " and check_result is null "
    callbackFn(res,oracle.connChaos,{sql})
  })

  return router
}